<?php
namespace Admin\Controller;
use Admin\Controller\CommonController;
class UsersController extends CommonController
{
    public function index()
    {
        $this->display();
    }

    /**
     * 用户列表
     */

    public function usersList(){
        if(!empty($_POST['search'])){
            $where['username'] = array('like','%'.trim($_POST['search']).'%');
        }
        $data['rows'] = M('user')
            ->where($where)
            ->page($_POST['page'],$_POST['rows'])
            ->select();
        $data['total'] = M('user')->count();
        $this->ajaxReturn($data);
    }

    /**
     * 用户修改
     */
  /*  public function editUsers(){
        $data['username'] = $_POST['username'];
        $data['gold'] = $_POST['gold'];
        $option = M('user')->where(['uid'=>$_POST['uid']])->save($data);
        $msg = [
            'success' => 1,
            'msg' => '数据修改成功！'
        ];
        if(!$option){
            $msg = [
                'success' => 0,
                'msg' => '数据修改失败！'
            ];
        }
        $this->ajaxReturn($msg);
    }*/

    /**
     * 删除用户
     */
   /* public function delUsers(){
        $where['uid'] = array('in',$_POST['id']);
        $option = M('user')->where($where)->delete();
        if($option){
            $data = [
                'status' => 1,
                'msg' => '数据删除成功'
            ];
        }else{
            $data = [
                'status' => 0,
                'msg' => '数据删除失败'
            ];
        }
        $this->ajaxReturn($data);
    }*/


    /**
     * 用户货币信息
     */
    public function currency(){
        $this->display();
    }

    public function userCurrency(){
        if(!empty($_POST['search'])){
            $where['u.username'] = array('like','%'.trim($_POST['search']).'%');
        }
        $data['rows'] = M('UserCurrency')->alias('u')
            ->join('left join '.C('DB_PREFIX').'currency c on u.currencyid=c.curyid')
            ->join('left join '.C('DB_PREFIX').'game g on c.gameid=g.gameid')
            ->join('left join '.C('DB_PREFIX').'user s on u.uid=s.uid')
            ->where($where)
            ->page($_POST['page'],$_POST['rows'])
            ->field('u.*,c.currency,g.game,s.username')
            ->select();

        $data['total'] = M('user_currency')->count();
        $this->ajaxReturn($data);
    }

    /**
     * 删除用户货币
     */
   /* public function delUCurrency(){
        $where['ucuryid']=array('in',$_POST['id']);
        $option = M('user_currency')
            ->where($where)
            ->delete();
        if($option){
            $data = [
                'status' => 1,
                'msg' => '数据删除成功'
            ];
        }else{
            $data = [
                'status' => 0,
                'msg' => '数据删除失败'
            ];
        }
        $this->ajaxReturn($data);
    }*/

}

